package com.dc.trans.steps.encrypt;

import java.util.List;
import java.util.Map;

import org.pentaho.di.core.CheckResultInterface;
import org.pentaho.di.core.Counter;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleXMLException;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.xml.XMLHandler;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.repository.ObjectId;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.shared.SharedObjectInterface;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.BaseStepMeta;
import org.pentaho.di.trans.step.StepDataInterface;
import org.pentaho.di.trans.step.StepInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInterface;
import org.w3c.dom.Node;

/**
* @ClassName: WebServiceInputMeta
* @Description: TODO
* @author zhangbinp
* @date Jul 16, 2012 11:26:53 AM
*/
public class EncryptMeta extends BaseStepMeta implements StepMetaInterface {

	private static Class<?> PKG = EncryptMeta.class; // for i18n purposes, needed by Translator2!!   $NON-NLS-1$
	private String stepName;
	private String encryptType;
	
	/*private String recipientInfo;
	private String lenData;
	private String strEncAlgId;
	private String strSignAlgId;
	private String dwFlagPart_1;
	private String dwFlagPart_2;
	private String dwFlagPart_3;*/
	
	/*public String getRecipientInfo() {
		return recipientInfo;
	}

	public void setRecipientInfo(String recipientInfo) {
		this.recipientInfo = recipientInfo;
	}

	public String getLenData() {
		return lenData;
	}

	public void setLenData(String lenData) {
		this.lenData = lenData;
	}

	public String getStrEncAlgId() {
		return strEncAlgId;
	}

	public void setStrEncAlgId(String strEncAlgId) {
		this.strEncAlgId = strEncAlgId;
	}

	public String getStrSignAlgId() {
		return strSignAlgId;
	}

	public void setStrSignAlgId(String strSignAlgId) {
		this.strSignAlgId = strSignAlgId;
	}

	public String getDwFlagPart_1() {
		return dwFlagPart_1;
	}

	public void setDwFlagPart_1(String dwFlagPart_1) {
		this.dwFlagPart_1 = dwFlagPart_1;
	}

	public String getDwFlagPart_2() {
		return dwFlagPart_2;
	}

	public void setDwFlagPart_2(String dwFlagPart_2) {
		this.dwFlagPart_2 = dwFlagPart_2;
	}

	public String getDwFlagPart_3() {
		return dwFlagPart_3;
	}

	public void setDwFlagPart_3(String dwFlagPart_3) {
		this.dwFlagPart_3 = dwFlagPart_3;
	}*/

	public static Class<?> getPKG() {
		return PKG;
	}

	public static void setPKG(Class<?> pkg) {
		PKG = pkg;
	}

	public String getEncryptType() {
		return encryptType;
	}

	public void setEncryptType(String encryptType) {
		this.encryptType = encryptType;
	}

	public String getStepName() {
		return stepName;
	}

	public void setStepName(String stepName) {
		this.stepName = stepName;
	}

	public EncryptMeta() {
		super();
	}

	@Override
	public void check(List<CheckResultInterface> remarks, TransMeta transMeta,
			StepMeta stepMeta, RowMetaInterface prev, String[] input,
			String[] output, RowMetaInterface info) {
		// TODO Auto-generated method stub

	}

	@Override
	public StepInterface getStep(StepMeta stepMeta,
			StepDataInterface stepDataInterface, int copyNr,
			TransMeta transMeta, Trans trans) {
		// TODO Auto-generated method stub
		return new Encrypt(stepMeta, stepDataInterface, copyNr, transMeta, trans);
	}

	@Override
	public void loadXML(Node stepnode, List<DatabaseMeta> databases,
			Map<String, Counter> counters) throws KettleXMLException {
		// TODO Auto-generated method stub
		readData(stepnode, databases);
	}
	private void readData(Node stepnode, List<? extends SharedObjectInterface> databases) throws KettleXMLException
	{
		try
		{
			stepName       = XMLHandler.getTagValue(stepnode, "stepName"); //$NON-NLS-1$
			encryptType       = XMLHandler.getTagValue(stepnode, "encryptType"); //$NON-NLS-1$
			/*recipientInfo = XMLHandler.getTagValue(stepnode, "recipientInfo");
			lenData = XMLHandler.getTagValue(stepnode, "lenData");
			strEncAlgId = XMLHandler.getTagValue(stepnode, "strEncAlgId");
			strSignAlgId = XMLHandler.getTagValue(stepnode, "strSignAlgId");
			dwFlagPart_1 = XMLHandler.getTagValue(stepnode, "dwFlagPart_1");
			dwFlagPart_2 = XMLHandler.getTagValue(stepnode, "dwFlagPart_2");
			dwFlagPart_3 = XMLHandler.getTagValue(stepnode, "dwFlagPart_3");
			*/	
		}
		catch(Exception e)
		{
			throw new KettleXMLException(BaseMessages.getString(PKG, "TransactionEndMeta.Exception.UnableToReadStepInfoFromXML"), e); //$NON-NLS-1$
		}
	}
	@Override
	public void readRep(Repository rep, ObjectId id_step,
			List<DatabaseMeta> databases, Map<String, Counter> counters)
			throws KettleException {
		try
		{
			stepName     = rep.getStepAttributeString(id_step, "stepName"); //$NON-NLS-1$
			encryptType     = rep.getStepAttributeString(id_step, "encryptType"); //$NON-NLS-1$
			/*recipientInfo     = rep.getStepAttributeString(id_step, "recipientInfo");
			lenData     = rep.getStepAttributeString(id_step, "lenData");
			strEncAlgId     = rep.getStepAttributeString(id_step, "strEncAlgId");
			strSignAlgId     = rep.getStepAttributeString(id_step, "strSignAlgId");
			dwFlagPart_1     = rep.getStepAttributeString(id_step, "dwFlagPart_1");
			dwFlagPart_2     = rep.getStepAttributeString(id_step, "dwFlagPart_2");
			dwFlagPart_3     = rep.getStepAttributeString(id_step, "dwFlagPart_3");*/
		}
		catch(Exception e)
		{
			throw new KettleException(BaseMessages.getString(PKG, "TransactionEndMeta.Exception.UnexpectedErrorReadingStepInfoFromRepository"), e); //$NON-NLS-1$
		}
	}

	@Override
	public void saveRep(Repository rep, ObjectId id_transformation,
			ObjectId id_step) throws KettleException {
		try
		{
			rep.saveStepAttribute(id_transformation, id_step, "stepName",stepName); //$NON-NLS-1$
			rep.saveStepAttribute(id_transformation, id_step, "encryptType",encryptType); //$NON-NLS-1$
			/*rep.saveStepAttribute(id_transformation, id_step, "recipientInfo",recipientInfo); //$NON-NLS-1$
			rep.saveStepAttribute(id_transformation, id_step, "lenData",lenData); //$NON-NLS-1$
			rep.saveStepAttribute(id_transformation, id_step, "strEncAlgId",strEncAlgId); //$NON-NLS-1$
			rep.saveStepAttribute(id_transformation, id_step, "strSignAlgId",strSignAlgId); //$NON-NLS-1$
			rep.saveStepAttribute(id_transformation, id_step, "dwFlagPart_1",dwFlagPart_1); //$NON-NLS-1$
			rep.saveStepAttribute(id_transformation, id_step, "dwFlagPart_2",dwFlagPart_2); //$NON-NLS-1$
			rep.saveStepAttribute(id_transformation, id_step, "dwFlagPart_3",dwFlagPart_3); //$NON-NLS-1$
*/		}
		catch(Exception e)
		{
			throw new KettleException(BaseMessages.getString(PKG, "TransactionEndMeta.Exception.UnableToSaveStepInfoToRepository")+id_step, e); //$NON-NLS-1$
		}
	}

	@Override
	public void setDefault() {

	}
	public String getXML()
	{
        StringBuilder retval = new StringBuilder(400);
		retval.append("    ").append(XMLHandler.addTagValue("stepName", stepName));
		retval.append("    ").append(XMLHandler.addTagValue("encryptType", encryptType));
		/*retval.append("    ").append(XMLHandler.addTagValue("recipientInfo", recipientInfo));
		retval.append("    ").append(XMLHandler.addTagValue("lenData", lenData));
		retval.append("    ").append(XMLHandler.addTagValue("strEncAlgId", strEncAlgId));
		retval.append("    ").append(XMLHandler.addTagValue("strSignAlgId", strSignAlgId));
		retval.append("    ").append(XMLHandler.addTagValue("dwFlagPart_1", dwFlagPart_1));
		retval.append("    ").append(XMLHandler.addTagValue("dwFlagPart_2", dwFlagPart_2));
		retval.append("    ").append(XMLHandler.addTagValue("dwFlagPart_3", dwFlagPart_3));*/
		return retval.toString();
	}

	@Override
	public StepDataInterface getStepData() {
		return new EncryptData();
	}


}
